package top.mczhengyi.xyblog.entity;

import lombok.Data;

@Data
public class Result {
    private Integer code;
    private String msg;
    private Object object;

    public Result() {

    }

    void setResult(ResultCode resultCode) {
        this.code = resultCode.getCode();
        this.msg = resultCode.getMessage();
    }

    public static Result success(Object object) {
        Result result = new Result();
        result.setResult(ResultCode.OK);
        result.setObject(object);
        return result;
    }

    public static Result success() {
        Result result = new Result();
        result.setResult(ResultCode.OK);
        return result;
    }

    public static Result fail(Integer code, String message) {
        Result result = new Result();
        result.setCode(code);
        result.setMsg(message);
        return result;
    }

    public static Result fail(ResultCode resultCode) {
        Result result = new Result();
        result.setResult(resultCode);
        return result;
    }
}
